package com.sunny.ynhz.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sunny.ynhz.R;
import com.sunny.ynhz.api.NetUrl;
import com.sunny.ynhz.bean.NewsBean;
import com.sunny.ynhz.ui.ImageActivity;

import java.util.List;

/**
 * Created by huhuan123 on 2018/1/8.
 */

public class NewsStaticAdapter extends BaseMultiItemQuickAdapter<NewsBean.DataBean.ContentBean, BaseViewHolder> {
    Context context;
    List<NewsBean.DataBean.ContentBean> newsData;
    int id = 0;
    Context mContext;

    public NewsStaticAdapter(List<NewsBean.DataBean.ContentBean> newsData, int id,Context context) {
        super(newsData);
        addItemType(1, R.layout.item_news_lay);
        this.newsData = newsData;
        this.id = id;
        this.mContext=context;

    }

    @Override
    protected void convert(BaseViewHolder helper, NewsBean.DataBean.ContentBean item) {
        helper.setText(R.id.tv_content, item.getTitle()).setText(R.id.tv_time, item.getCreateDate());
        ImageView img = helper.getView(R.id.img_news);
        if (id == 12||id==1) {
            img.setVisibility(View.GONE);
        } else {
            Glide.with(mContext).load(NetUrl.baseImageUrl + item.getPictureUrl())
                    .placeholder(R.mipmap.ic_deafult)
                    .error(R.mipmap.ic_deafult)
                    .centerCrop()
                    .into(img);
        }
        img.setOnClickListener(view-> {
              String url=NetUrl.baseImageUrl  + item.getPictureUrl();
                Intent intent=new Intent(mContext, ImageActivity.class);
                intent.putExtra("pic_path",url);
                intent.putExtra("path",url);
                mContext.startActivity(intent);
        });

    }
}
